package com.xique.api.service.biz.service.impl;

import com.xique.api.bean.request.device.DeviceAddRequest;
import com.xique.api.bean.request.device.DeviceListRequest;
import com.xique.api.service.biz.service.IDeviceBizService;
import com.xique.common.core.utils.OrikaUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.api.RemoteDeviceService;
import com.xique.door.api.request.device.RemoteDeviceAddRequest;
import com.xique.door.api.request.device.RemoteDeviceListRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author shd
 * @create 2022/3/10 20:11
 */
@Service
public class DeviceBizServiceImpl implements IDeviceBizService {

    @Autowired
    private RemoteDeviceService deviceService;

    @Override
    public AjaxResult getDeviceList(DeviceListRequest request) {

        Long projectId = SecurityUtils.getForeignId();
        RemoteDeviceListRequest listRequest = OrikaUtil.convert(request, RemoteDeviceListRequest.class);
        listRequest.setProjectId(projectId);

        return deviceService.getDeviceList(listRequest);
    }

    @Override
    public AjaxResult addDevice(DeviceAddRequest request) {

        Long projectId = SecurityUtils.getForeignId();
        RemoteDeviceAddRequest addRequest = OrikaUtil.convert(request, RemoteDeviceAddRequest.class);
        addRequest.setProjectId(projectId);

        return deviceService.addDevice(addRequest);
    }
}
